// routes/routes.go
package routes

import (
	"myapi/controllers"
	"myapi/utils"

	"github.com/gin-gonic/gin"
)

// SetupRoutes 配置 API 路由
func SetupRoutes(r *gin.Engine) {
	// 创建控制器实例
	userController := controllers.NewUserController()
	subjectController := controllers.NewSubjectController()
	scoreController := controllers.NewScoreController()
	orderController := controllers.NewOrderController()
	pdfController := controllers.NewPDFController()
	uploadController := controllers.NewUploadController()
	r.Use(utils.CORSMiddleware())
	// API 版本分组
	v1 := r.Group("/api/v1")

	{
		// 用户相关路由
		users := v1.Group("/users")
		{
			users.POST("/register", userController.Register)
			users.GET("/list", userController.GetUsers)
			users.GET("/list/:id", userController.GetUser)
			users.POST("/update/:id", userController.UpdateUser)
			users.DELETE("/delete/:id", userController.DeleteUser)
		}
		// 科目相关路由
		subjects := v1.Group("/subjects")
		{
			subjects.POST("/add", subjectController.CreateSubject)
			subjects.GET("/list", subjectController.GetSubjects)
			subjects.GET("/list/:id", subjectController.GetSubject)
			subjects.POST("/update/:id", subjectController.UpdateSubject)
			subjects.DELETE("/delete/:id", subjectController.DeleteSubject)
		}
		teachers := v1.Group("/teachers")
		{
			teachers.POST("/register", userController.Register)
		}
		// 成绩相关路由
		scores := v1.Group("/scores")
		{
			scores.POST("/add", scoreController.CreateScore)
			scores.GET("/list", scoreController.GetScores)
			scores.GET("/list/:id", scoreController.GetScore)
			scores.POST("/update/:id", scoreController.UpdateScore)
			scores.DELETE("/delete/:id", scoreController.DeleteScore)
			scores.GET("/topThree", scoreController.GetTopThreeScores)
			scores.GET("/lowestScore", scoreController.GetLowestScore)
		}

		// 订单相关路由
		orders := v1.Group("/orders")
		{
			orders.POST("/add", orderController.CreateOrder)
			orders.GET("/list", orderController.GetOrders)
			orders.GET("/list/:id", orderController.GetOrder)
			orders.PUT("/update/:id/status", orderController.UpdateOrderStatus)
			orders.DELETE("/del/:id", orderController.DeleteOrder)
			orders.GET("/statistics", orderController.GetOrderStatistics)
		}

		// PDF生成相关路由
		pdf := v1.Group("/pdf")
		{
			pdf.GET("/order", pdfController.GenerateOrderPDF)
		}
		// 图片上传oss链接
		upload := v1.Group("/upload")
		{
			// 单文件上传
			upload.POST("/image", uploadController.UploadImage)
			// 多文件上传
			upload.POST("/multiple", uploadController.UploadMultipleImages)
		}
	}
}
